def listToString(l):
    if len(l)==0:
        return ""
    stri =""
    for i in range (len(l)):
        stri = "%s%s%s" %(stri, str(l[i]), "\n")
    return stri

def connectAdmin(pseudo, password):
    global adminConnected
    if adminConnected == False and adminPseudo == pseudo and adminPassword == password:
        adminConnected = True
        return 1
    else:
        return 0

def disconnectAdmin(pseudo):
    global adminConnected
    adminConnected = False

def connect(pseudo, password):
    global users
    if users.has_key(pseudo):
        if users[pseudo] == password:
            if (pseudo in connectedUsers) == False:
                connectedUsers.append(pseudo)
                return 1
            else:
                return 0
        else:
            return 0
    else:
        return 0

def disconnect(pseudo):
    global connectedUsers
    connectedUsers.remove(pseudo)

def addUser(pseudo, password):
    global users
    if users.has_key(pseudo):
        return 0
    else:
        users[pseudo] = password
        return 1

def deleteUser(pseudo):
    global users
    if users.has_key(pseudo) == False:
        return 0
    else:
        del users[pseudo]
        return 1

def getUsers():
    global users
    return listToString(users.keys())

#programme principal

messages = []
users = {}
connectedUsers = []

adminConnected = False
adminPseudo = 'admin'
adminPassword = 'admin' 
